   /**
     * 积分排行榜
     */
    /**
     * 静态常量
     * 组别ID
     * 逍遥三界->1
     * 纵横武林->2
     * 闯荡江湖->3
     * 初入凡尘->4
     * 三界战神->5
     */
    const GroupId = Object.freeze({
      [Symbol.for('xysj')]:1,
      [Symbol.for('zhwl')]:2,
      [Symbol.for('cdjh')]:3,
      [Symbol.for('crfc')]:4,
      [Symbol.for('sjzs')]:5
  });
  /**
   * 接口
   */
  class API  {
      
      constructor(){
          this.baseUrl = 'https://comp-sync.webapp.163.com/g17lzhd';
          this.season = 4;
      }
      //获取赛季列表
      getSeason(){
          return new Promise((resolve,reject)=>{
              $.ajax({
                  url:`${this.baseUrl}/gsync_keys`,
                  type:'GET',
                  dataType:'jsonp',
                  timeout:10000,
                  error(){
                      alert('网络繁忙，请稍后再试');
                  },
                  success(data){
                      resolve(data);
                  }
              })
          })
      }
      //获取查询数据
      getPageList(season,game,subgroup,page,per_page,search_key){
          return new Promise((resolve,reject)=>{
              $.ajax({
                  url: `${this.baseUrl}/gsync_paged_list`,
                  type: 'GET',
                  dataType: 'jsonp',
                  data:{
                      season,
                      subgroup,
                      game,
                      page,
                      per_page,
                      search_key
                  },
                  success(data){
                      resolve(data);
                  }
              })
          })
      }
  };
  var jfph =  new Vue({
      el:'#JSJsph',
      data:{
          goPageNumber: '',
          searchTimer: null,
          searchField:'',
          api: null,//API对象
          page: 1,//当前页数
          totalPage: 1,//总共页数
          pageNum: 10,//默认页面显示条数 若非测试无需修改
          currentServer: 'free',//当前服务器
          currentGroup: { //当前分组
              // txt: '三界战神',
              // id: 'sjzs'
              txt:'逍遥三界',
              id: 'xysj'
          },
          currentGroups: [],
          currentGroups1: [],
          /**
           * gameServer->服务器
           * teamName->战队 名称
           * leaderName->队长 昵称
           * integral->积分
           * 
           * { 
           *  gameServer: '时间服',
           *  teamName: '战队名称七个字',
           *  leaderName: '队长名六个字',
           *  integral: 1048
           * }
           */
          serverClicked: false,
          groupClicked: false
      },
      mounted: function(){
          var that = this;
          that.api = new API();
          //请求默认的服务器和分组对应的数据
          that.mAjax({updateTotalPage:true});
      },
      methods:{
          goPage(){
              if(this.goPageNumber> this.totalPage){
                  PopDialog.Alert('超出页码!');
                  return;
              }
              this.page = this.goPageNumber;
              this.mAjax();
          },
          updateGroupArr(data){
              //更新组别显示数组
              let groupArr = data['data'];
              let that = this;
              that.currentGroups = [];
//              that.t.currentGroups1 = [];
              if(that.page == 1){
                if(groupArr.length>3){
                  that.currentGroups1 = [];
                }
                
                for(group of groupArr){
                    that.currentGroups1.push({
                        gameServer: group['server'],
                        teamName: group['team_name'],
                        leaderName: group['leader_name'],
                        integral: group['score']
                    });
                }
              }
              for(group of groupArr){
                  that.currentGroups.push({
                      gameServer: group['server'],
                      teamName: group['team_name'],
                      leaderName: group['leader_name'],
                      integral: group['score']
                  });
              }
          },
          prevPage(){
              var that = this;
              if(that.page == 1){
                  return;
              }
              that.page--;
              that.mAjax();
          },
          nextPage(){
              var that = this;
              if(that.page == that.totalPage){
                  return;
              }
              that.page++;
              that.mAjax();
          },
          mAjax(updateTotalPage = false){
              let that = this;
              
              if(updateTotalPage){
                  that.page = 1;
              }
           //   console.log(that.currentServer,GroupId[Symbol.for(that.currentGroup.id)]);
               that.api.getPageList(that.api.season,that.currentServer,GroupId[Symbol.for(that.currentGroup.id)],that.page,that.pageNum,that.searchField).then(data=>{
                      
                      if(data.status){
                          that.updateGroupArr(data);
                          if(updateTotalPage){
                            that.totalPage = Math.ceil(data['total_num'] / that.pageNum ) == 0 ? 1 : Math.ceil(data['total_num'] / that.pageNum );//总共页数
                          }
                      }
                   }
               )
               
          },
          jfcServerClick(e){
             this.serverClicked = !this.serverClicked;
          },
          jscGroupClick(e){
              this.groupClicked = !this.groupClicked;
          },
          groupItemClick(e){  
            this.searchField = ''
              let $ele = $(e.target),
                  txt = $ele.text(),
                  group = $ele.data('group');
              this.currentGroup.txt = txt;
              this.currentGroup.id = group;
             // console.log( this.currentGroup.txt ,this.currentGroup.id);
              this.mAjax({updateTotalPage:true});

              this.groupClicked = false;
              this.serverClicked = false;
          },
          gameItemClick(e){
      this.searchField = ''
               /**
               * 服务器切换
               * 免费服(free)对应->三界战神
               * 时间服(time)对应->逍遥三界
               */
              let game = $(e.target).data('game');
              this.currentServer =  game;
              if(game == 'free'){
                this.currentGroup = {
                      txt: '逍遥三界',
                      id: 'xysj'
                  }
                  
              }else{
                  this.currentGroup = {
                      txt: '三界战神',
                      id: 'sjzs'
                  }
              }
              this.mAjax({updateTotalPage:true});
              this.groupClicked = false;
              this.serverClicked = false;
               
          },
          searchInput(e){
              let that = this;
              if(that.searchTimer){
                  clearTimeout(that.searchTimer);
              }
              that.searchTimer = setTimeout(()=>{
                  that.mAjax({updateTotalPage:true});
              },800);
              
              
              
          }
      },
      computed:{
          gameText () {
              return this.currentServer=='free'?'免费服':'时间服';
          },
          getRank1 () {
              /**
               * 第一名信息
               */
              return this.currentGroups1[0];
          },
          getRank2 () {
              /**
               * 第二名信息
               */
              return this.currentGroups1[1];
          },
          getRank3 () {
              /**
               * 第三名信息
               */
              return this.currentGroups1[2];
              
          }
      }
  });